<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2007/01/23 19:36:10 $)
// $RCSfile: index.php,v $ : $Revision: 1.13 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


define("SWIFT_AREA", 50);

if (defined("SWIFTCUSTOMPATH"))
{
	chdir(SWIFTCUSTOMPATH);
} else {
	chdir('./../');
}
require_once ("./swift.php");

if ($_REQUEST["_ca"] == "login") {
	$staffid = $staffauth->authenticate(urldecode($_REQUEST["username"]), strtolower($_REQUEST["password"]), false, false);
	if (!empty($staffid))
	{
		require_once ("./includes/functions_xml.php");
		$xml = new XML;

		$session->insertSession(SESSION_WINAPP, $staffid);

		$xml->addParentTag("swiftwinapp");
		$xml->addTag("sessionid", $_SWIFT["session"]["sessionid"]);
		
		// Hardcoded module event callback, will just return false if module isnt there or isnt registered
		$events->triggerCallback("livesupport", "winappLogin");
	
		$xml->addTag("producturl", $_SWIFT["settings"]["general_producturl"]);
		$xml->endTag("swiftwinapp");
		$xml->echoXMLUTFWinapp();

		require_once ("./includes/functions_cron.php");
		$cron = new Cron;

		$cron->runPendingTasks();

} else {
		// Authentication Failed
		echoWinappData("-2");
	}
} else if ($_REQUEST["_ca"] == "logout") {
	if (!$session->start(SESSION_WINAPP)) {
		// Session expired
		echoWinappData("-1");
		exit;
	}		

	$events->triggerCallback("livesupport", "winappLogout");

	$session->logoutSession(SESSION_WINAPP);
	echoWinappData("1");
} else {
	if (!$session->start(SESSION_WINAPP)) {
		// Session expired
		echoWinappData("-1");
		exit;
	}		

	$events->triggerEvent(EVENT_WINAPP);
}
?>